package com.xian.dynasties.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xian.common.annotation.Log;
import com.xian.common.core.controller.BaseController;
import com.xian.common.core.domain.AjaxResult;
import com.xian.common.enums.BusinessType;
import com.xian.dynasties.domain.TDynasties;
import com.xian.dynasties.service.ITDynastiesService;
import com.xian.common.utils.poi.ExcelUtil;
import com.xian.common.core.page.TableDataInfo;

/**
 * 朝代信息Controller
 * 
 * @author jimihua
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/dynasties/dynasties")
public class TDynastiesController extends BaseController
{
    @Autowired
    private ITDynastiesService tDynastiesService;

    /**
     * 查询朝代信息列表
     */
    @PreAuthorize("@ss.hasPermi('dynasties:dynasties:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDynasties tDynasties)
    {
        startPage();
        List<TDynasties> list = tDynastiesService.selectTDynastiesList(tDynasties);
        return getDataTable(list);
    }

    /**
     * 导出朝代信息列表
     */
    @PreAuthorize("@ss.hasPermi('dynasties:dynasties:export')")
    @Log(title = "朝代信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDynasties tDynasties)
    {
        List<TDynasties> list = tDynastiesService.selectTDynastiesList(tDynasties);
        ExcelUtil<TDynasties> util = new ExcelUtil<TDynasties>(TDynasties.class);
        util.exportExcel(response, list, "朝代信息数据");
    }

    /**
     * 获取朝代信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('dynasties:dynasties:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tDynastiesService.selectTDynastiesById(id));
    }

    /**
     * 新增朝代信息
     */
    @PreAuthorize("@ss.hasPermi('dynasties:dynasties:add')")
    @Log(title = "朝代信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDynasties tDynasties)
    {
        return toAjax(tDynastiesService.insertTDynasties(tDynasties));
    }

    /**
     * 修改朝代信息
     */
    @PreAuthorize("@ss.hasPermi('dynasties:dynasties:edit')")
    @Log(title = "朝代信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDynasties tDynasties)
    {
        return toAjax(tDynastiesService.updateTDynasties(tDynasties));
    }

    /**
     * 删除朝代信息
     */
    @PreAuthorize("@ss.hasPermi('dynasties:dynasties:remove')")
    @Log(title = "朝代信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDynastiesService.deleteTDynastiesByIds(ids));
    }
}
